
************************************************
*** Table on provisions and ETRs	     ***
************************************************

*Read
u "$cur_sample" if inlist(year,2016,2019), clear
do $cleaning/renameSOI

*Keep ETR firms 	
keep if pidom_soi>0

*Set panel 
gegen t = group(year)
tsset firmid t

*ETR 
g etr = uscetr_soi*100 
g letr = ln(1 + etr)
g detr = d.etr
g dletr = d.letr

*Keep only 2016 + the ETR change 
foreach i in detr dletr {
	gegen x = max(`i'), by(firmid)
	replace `i' = x 
	drop x
}
keep if year==2016

*MTR brackets
g brk0 = taxable_income==0
g brk1 = taxable_income>0 & taxable_income<5e4
g brk2 = taxable_income>=5e4 & taxable_income<7.5e4
g brk3 = taxable_income>=7.5e4 & taxable_income<10e4
g brk4 = taxable_income>=1e5 & taxable_income<3.35e5
g brk5 = taxable_income>=.335e6 & taxable_income<10e6
g brk6 = taxable_income>=10e6 & taxable_income<15e6
g brk7 = taxable_income>=15e6 & taxable_income<18e6
g brk8 = taxable_income>=18e6 & !mi(taxable_income)
g bracket = 0 if brk0 
forval i = 1/8 {
	replace bracket = `i' if brk`i'
} 

*Low vs. High MTR brackets 
g brlo = bracket<=2
g brhi = bracket>=4
g brmi = !brlo & !brhi & !mi(taxable_income)
label var brlo "<=2nd MTR Bracket"
label var brhi ">=4th MTR Bracket"
*AMT 
g amt = alternative_minimum_tax>0 & !mi(alternative_minimum_tax)
label var amt "AMT"

*NOL 
g nol_able = nol_carryforward_available>0 & !mi(nol_carryforward_available)
label var nol_able "NOL"

*Expensing 
cap drop bonus
g bonus = (inv)>0 & !mi(inv)
label var bonus "Bonus (Inv>0)"

*DPAD 
g dpad = dpad_amt>0 & !mi(dpad_amt)
label var dpad "DPAD"

*Interest limitation
g net_intrst = max(0,interest_paid - interest_received)
g intlim = net_intrst>.3*(ebitda) & taxable_income>0
label var intlim "Interest Limitation"

*Foreign provisions
label var mne "Multinational"

*Reconstruct a couple variables
g etr_post = etr+detr
g payroll = cost_of_labor + salaries_wages_nde + compensation_officers 
*Winsorize ETR change 
winsor2 detr, cuts(5 95) replace
winsor2 etr, cuts(0 95) replace
winsor2 etr_post, cuts(0 95) replace

g sallo = salq==1
g salmd = salq==2
g salhi = salq==3

g naics2_mod = naics2
	replace naics2_mod = 30 if naics2==31 | naics2==32 | naics2==33
	replace naics2_mod = 44 if naics2==45

g ind_rea = naics2_mod==53
g ind_mfg = naics2_mod==30
g ind_con = naics2_mod==23
g ind_prf = naics2_mod==54
g ind_ret = naics2_mod==44

label var everpublic "Public"
label var sallo "Rev<90th percentile"
label var salmd "Rev 90th-95th"
label var salhi "Rev>95th"
label var ind_rea "Real Estate"
label var ind_mfg "Manufacturing"
label var ind_con "Construction"
label var ind_prf "Professional Services"
label var ind_ret "Retail Trade"
*Multivariate regression, all firms
global X16 mne everpublic salmd salhi ind_rea ind_mfg ind_con //brlo brhi amt nol_able bonus dpad intlim mne 

eststo clear
eststo all: reghdfe detr $X16 [pw=weightSOI], cluster(firmid) noab
estadd local fe "No"
estadd local w "No"
local Nall = string(e(N),"%9.0fc")
local ref = string(_b[_cons],"%9.2f")
local refse = string(_se[_cons],"%9.2f")

*Coefficient plot
coefplot all, keep(${X16}) levels(95)  ///
	text(.4 -17 "{bf: 2016 Firm Characteristic}", size(small)) ///
	xtitle("PP change in ETR, 2016-2019") ///
	note("N = `Nall' SOI firms" "Constant: `ref', se=`refse'", pos(6) size(small))
graph export "$results/provisions_firmchar.pdf", replace


